
//Import an entire module's contents
import * as myModule from '/modules/my-module.js';
myModule.doAllTheAmazingThings();

//Import single module
import {myExport} from '/modules/my-module.js';
//Import multiple exports from module
import {foo, bar} from '/modules/my-module.js';


import {reallyReallyLongModuleExportName as shortName} from '/modules/my-module.js';
shortName.doSomething();

//Import a module for its side effects only
import '/modules/my-module.js';


//Importing defaults
//It is possible to have a default export (whether it is an object, a function, a class, etc.).
//The import statement may then be used to import such defaults.
//The simplest version directly imports the default:
import myDefault from '/modules/my-module.js';
myDefault.doSomething();


/*
[ref](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)

export { name1, name2, …, nameN };
export { variable1 as name1, variable2 as name2, …, nameN };
export let name1, name2, …, nameN; // also var
export let name1 = …, name2 = …, …, nameN; // also var, const
export function FunctionName(){...}
export class ClassName {...}

export default expression;
export default function (…) { … } // also class, function*
export default function name1(…) { … } // also class, function*
export { name1 as default, … };

export * from …;
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
export { default } from …;
* */

//example for export function
function getJSON(url, callback) {
    let xhr = new XMLHttpRequest();
    xhr.onload = function () {
        callback(this.responseText)
    };
    xhr.open('GET', url, true);
    xhr.send();
}

export function getUsefulContents(url, callback) {
    getJSON(url, data => callback(JSON.parse(data)));
}


//Named exports:
// exports a function declared earlier
export { getUsefulContents };

// exports a constant
    export const foo = Math.sqrt(2);
// Default exports (function):
export default function() {}
// Default exports (class):
export default class {}


